package com.yx.front.handler;

import com.alibaba.fastjson.JSON;
import com.yx.front.config.global.CommonResult;
import com.yx.front.utils.WebUtils;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author YangXiong
 */
@Component
public class AccessDeniedHandlerImpl implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) {
        CommonResult<String> result = new CommonResult<>("权限不足");
        String json = JSON.toJSONString(result);
        WebUtils.renderString(response,json);

    }
}

